<template>
  <Dialog v-model="dialogVisible" :max-height="500" :scroll="true" title="司机详情" width="800">
    <el-descriptions :column="2" border>
      <el-descriptions-item label="司机编号" min-width="120">
        {{ detailData.id }}
      </el-descriptions-item>
      <el-descriptions-item label="用户名称">
        {{ detailData.username }}
      </el-descriptions-item>
      <el-descriptions-item label="司机姓名">
        {{ detailData.nickname }}
      </el-descriptions-item>
      <el-descriptions-item label="用户昵称">
        {{ detailData.nickname }}
      </el-descriptions-item>
      <el-descriptions-item label="手机号码">
        {{ detailData.mobile }}
      </el-descriptions-item>
      <el-descriptions-item label="邮箱">
        {{ detailData.email }}
      </el-descriptions-item>
      <el-descriptions-item label="驾驶证号">
        {{ detailData.driverLicenseNo }}
      </el-descriptions-item>
      <el-descriptions-item label="驾驶证类型">
        {{ detailData.licenseType }}
      </el-descriptions-item>
      <el-descriptions-item label="用户性别">
        <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="detailData.sex" />
      </el-descriptions-item>
      <el-descriptions-item label="创建时间">
        {{ formatDate(detailData.createTime) }}
      </el-descriptions-item>
      <el-descriptions-item label="状态">
        <el-tag v-if="detailData.status === 0" type="success">正常</el-tag>
        <el-tag v-else type="danger">停用</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="工作状态">
        <el-tag v-if="detailData.workStatus === 0" type="info">空闲</el-tag>
        <el-tag v-else-if="detailData.workStatus === 1" type="warning">工作中</el-tag>
        <el-tag v-else type="success">休息</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="更新时间">
        {{ formatDate(detailData.updateTime) }}
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.remark" label="备注" :span="2">
        {{ detailData.remark }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>
<script lang="ts" setup>
import { formatDate } from '@/utils/formatTime'
import { DICT_TYPE } from '@/utils/dict'
import * as DriverApi from '@/api/system/driver'

defineOptions({ name: 'SystemDriverDetail' })

const dialogVisible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as DriverApi.DriverVO) // 详情数据

/** 打开弹窗 */
const open = async (data: DriverApi.DriverVO) => {
  dialogVisible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    detailData.value = data
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
